package cn.com.acca.ma.service.impl;

import cn.com.acca.ma.common.util.PropertiesUtil;
import cn.com.acca.ma.enumeration.PythonApiResult;
import cn.com.acca.ma.model.StockInfo;
import cn.com.acca.ma.service.StockInfoService;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;

public class StockInfoServiceImpl extends BaseServiceImpl<StockInfoServiceImpl, StockInfo> implements StockInfoService {

    /**
     * 更新股票名称
     */
    @Override
    public void updateNameInStockInfo() {
        String filePath = PropertiesUtil.getValue(ETF_TRANSACTION_DATA_PROPERTIES,"adam3.api.file.path");
        String updateNameInStockInfo = PropertiesUtil.getValue(STOCK_INFO_PROPERTIES,"stockInfo.name.updateNameInStockInfo");
        String date = PropertiesUtil.getValue(STOCK_INFO_PROPERTIES,"stockInfo.name.date");

        logger.info("更新股票名称，日期[" + date + "]");

        Process process = null;
        BufferedReader in = null;
        try {
            // 调用adam3的接口，更新股票名称
            String[] parameterArray = new String[]{"python", filePath, "api", updateNameInStockInfo, date};
            process = Runtime.getRuntime().exec(parameterArray);
            in = new BufferedReader(new InputStreamReader(process.getInputStream(), "gbk"));
            StringBuffer stringBuffer = new StringBuffer();
            String actionStr;
            while ((actionStr = in.readLine()) != null) {
                stringBuffer.append(actionStr);
                logger.debug("接口返回值：" + actionStr);
            }
            if (!PythonApiResult.FINISH.getCode().equals(stringBuffer.toString())){
                logger.warn("调用adam3的接口，更新股票名称，返回值：" + stringBuffer);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public String listToString(List list) {
        return null;
    }
}
